package framework.widgets;
import pixi.core.textures.Texture;
import pixi.core.sprites.Sprite;

typedef OnClick = Void->Void;

class SpriteButton extends Sprite{

	private var _sx:Float;
	private var _sy:Float;

	public var onClick:OnClick;

	public function new(texture:Texture) {
		super(texture);

		this.interactive = true;
		this.buttonMode = true;
		this.anchor.set(0.5);


		this.on("pointerdown", this.onPointerDown);
		this.on("pointerup", this.onPointerUp);
		this.on("pointerupoutside", this.onPointerCancel);
		this.on("pointerout", this.onPointerCancel);
	}

	private function onPointerDown(){
		_sx = this.scale.x;
		_sy = this.scale.y;
		this.scale.set(_sx * 1.1, _sy * 1.1);
	}

	private function onPointerUp(){
		this.scale.set(_sx, _sy);
		if(onClick != null){
			onClick();
		}
	}

	private function onPointerCancel(){
		this.scale.set(_sx, _sy);
	}

}
